/*
 * @Author: fhw
 * @Date: 2022-07-28 16:13:15
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-02-04 21:53:09
 * @Description:
 */
import { Controller, Get, Post, Body, HttpCode, Query, UseGuards } from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport'
import { ApiResponse, ApiOperation, ApiBody, ApiTags, ApiQuery } from '@nestjs/swagger'
import { ArticleCategoryService } from './article_category.service'
import { ArticleCategoryDto, UpdateCategoryDto, DelteIdDto, CreateCategoryDto } from './dto/article_category.dto'
import { CategoryResult } from './entities/article_category.entity'

@Controller('articleCategory')
@ApiTags('文章分类')
export class ArticleCategoryController {
  constructor(private readonly articleCategoryService: ArticleCategoryService) {}
  /** 分类 */
  @HttpCode(200)
  @Get('/getArticleCategory')
  @ApiResponse({
    status: 200,
    description: '分类列表',
    type: CategoryResult,
  })
  @ApiOperation({ summary: '获取文章分类', operationId: 'getArticleCategory' })
  @UseGuards(AuthGuard('jwt'))//jwt策略，身份鉴权
  getArticleCategory(@Query() params: ArticleCategoryDto) {
    return this.articleCategoryService.getArticleCategory(params)
  }
  @HttpCode(200)
  @Post('/createCategory')
  @ApiQuery({
    description: '创建分类',
    type: CreateCategoryDto,
  })
  @ApiBody({
    description: '创建分类',
    type: CreateCategoryDto,
  })
  @ApiOperation({ summary: '创建分类', operationId: 'createCategory' })
  @UseGuards(AuthGuard('jwt'))//jwt策略，身份鉴权
  createCategory(@Body() body: CreateCategoryDto) {
    return this.articleCategoryService.createCategory(body)
  }
  @HttpCode(200)
  @Post('/updateCategory')
  @ApiQuery({
    description: '更新分类',
    type: UpdateCategoryDto,
  })
  @ApiBody({ description: '更新分类', type: UpdateCategoryDto })
  @ApiOperation({ summary: '更新分类', operationId: 'updateCategory' })
  @UseGuards(AuthGuard('jwt'))//jwt策略，身份鉴权
  updateCategory(@Body() body: UpdateCategoryDto) {
    return this.articleCategoryService.updateCategory(body)
  }
  @HttpCode(200)
  @Post('/delCategory')
  @ApiQuery({
    description: '删除分类',
    type: DelteIdDto,
  })
  @ApiBody({ description: '删除分类', type: DelteIdDto })
  @ApiOperation({ summary: '删除分类', operationId: 'delCategory' })
  @UseGuards(AuthGuard('jwt'))//jwt策略，身份鉴权
  delCategory(@Body() body: DelteIdDto) {
    return this.articleCategoryService.delCategory(body)
  }
}
